# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_statistics.py
# @Time      :2020/12/7 10:28
# @Author    :Zhoujirong
# @Desc      : 企业统计分析管理
import time

import parameterized
import datetime
from biz.flow.ent_statistics import EntStatisticsRequest
from common.log import Log
from common.params_operator import Param
from biz.cases.base_case import BaseCase
from common.utils import download
class TestEntStatistics(BaseCase):
    data_file_name = 'per_statistics.yaml'
    @classmethod
    def setUpClass(cls):
       cls.cookie = BaseCase().get_token()

    @parameterized.parameterized.expand(Param.from_excel('statisticsbyuser.xls'))
    def test_statistics_by_user(self,month0,
                                        year0,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,day0,day1,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,
                                        check,desc):
        self._testMethodDoc = desc
        ret = EntStatisticsRequest.statistics_by_user(day0,month0,
                                        year0,day1,
                                        month1,year1,
                                        search_EQ_userType,
                                        search_EQ_batchFlag,
                                        search_EQ_source,
                                        search_EQ_autharchiveId,
                                        search_EQ_status,
                                        search_EQ_formReport,
                                        search_EQ_queryType,
                                        search_EQ_queryFormat,
                                        search_GTE_updateTime_DATE,
                                        search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)

    @parameterized.parameterized.expand(Param.from_excel('statisticsbyorg.xls'))
    def test_statistics_by_org(self,day0,month0,year0,
                                day1,month1,
                                year1,search_EQ_operOrg,
                                search_EQ_batchFlag,
                                search_EQ_source,
                                search_EQ_autharchiveId,
                                search_EQ_status,
                                search_EQ_formReport,
                                search_EQ_queryFormat,
                                search_GTE_updateTime_DATE,
                                search_LTE_updateTime_DATE,check,desc):
        self._testMethodDoc = desc
        ret = EntStatisticsRequest.statistics_by_org(day0,month0,year0,
                                day1,month1,
                                year1,search_EQ_operOrg,
                                search_EQ_batchFlag,
                                search_EQ_source,
                                search_EQ_autharchiveId,
                                search_EQ_status,
                                search_EQ_formReport,
                                search_EQ_queryFormat,
                                search_GTE_updateTime_DATE,
                                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)

    @parameterized.parameterized.expand(Param.from_excel('statisticsbyrule.xls'))
    def test_statistics_by_rule(self,search_GTE_startDate_DATE,
                                search_GTE_alertDate_DATE,
                                search_IN_deptCode,check,desc):
        self._testMethodDoc = desc
        ret = EntStatisticsRequest.statistics_by_rule(search_GTE_startDate_DATE,
                                                search_GTE_alertDate_DATE,
                                                search_IN_deptCode,self.cookie)
        Log.info(ret)

    def test_exportbyuser(self):
        '''按用户统计导出'''
        day0 = datetime.date.today()
        month0 = self.file_data.get('month0')
        year0 = self.file_data.get('year0')
        day1 = datetime.date.today()
        month1 = self.file_data.get('month1')
        year1 = self.file_data.get('year1')
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = datetime.date.today()
        search_LTE_updateTime_DATE = datetime.date.today()
        ret = EntStatisticsRequest.exportbyuser( day0,
                     month0, year0,
                     day1, month1,
                     year1,
                     search_EQ_userType,
                     search_EQ_batchFlag,
                     search_EQ_source,
                     search_EQ_autharchiveId,
                     search_EQ_status,
                     search_EQ_formReport,
                     search_EQ_queryFormat,
                     search_GTE_updateTime_DATE,
                     search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        size = download('企业按用户统计报表dhcc_ent_statisticsDtest_exportbyuser%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_byuser_nodate(self):
        '''按用户统计无起始结束日期'''
        day0 = ''
        month0 = ''
        year0 = ''
        day1 = ''
        month1 = ''
        year1 = ''
        search_EQ_queryType = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = ''
        search_LTE_updateTime_DATE = ''
        ret = EntStatisticsRequest.statistics_by_user(day0,month0,
                year0,day1,
                month1,year1,
                search_EQ_userType,
                search_EQ_batchFlag,
                search_EQ_source,
                search_EQ_autharchiveId,
                search_EQ_status,
                search_EQ_formReport,
                search_EQ_queryType,
                search_EQ_queryFormat,
                search_GTE_updateTime_DATE,
                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('请选择开始时间及结束时间', ret.msg)

    def test_byuser_nodata(self):
        '''按用户统计无数据'''
        day0 = '2009-07-12'
        month0 = ''
        year0 = ''
        day1 = '2009-07-12'
        month1 = ''
        year1 = ''
        search_EQ_queryType = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = '2009-07-12'
        search_LTE_updateTime_DATE = '2009-07-12'
        ret = EntStatisticsRequest.statistics_by_user(day0,month0,
                year0,day1,
                month1,year1,
                search_EQ_userType,
                search_EQ_batchFlag,
                search_EQ_source,
                search_EQ_autharchiveId,
                search_EQ_status,
                search_EQ_formReport,
                search_EQ_queryType,
                search_EQ_queryFormat,
                search_GTE_updateTime_DATE,
                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('未查询到相关数据', ret.msg)

    def test_byuser_day(self):
        '''按用户统计--天'''
        tmp = time.strftime('%Y-%m-%d',time.localtime())
        day0 = tmp
        month0 = ''
        year0 = ''
        day1 = tmp
        month1 = ''
        year1 = ''
        search_EQ_queryType = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_user(day0,month0,
                year0,day1,
                month1,year1,
                search_EQ_userType,
                search_EQ_batchFlag,
                search_EQ_source,
                search_EQ_autharchiveId,
                search_EQ_status,
                search_EQ_formReport,
                search_EQ_queryType,
                search_EQ_queryFormat,
                search_GTE_updateTime_DATE,
                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual(tmp, ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_byuser_month(self):
        '''按用户统计--月'''
        tmp = time.strftime('%Y-%m',time.localtime())
        day0 = ''
        month0 = tmp
        year0 = ''
        day1 = ''
        month1 = tmp
        year1 = ''
        search_EQ_queryType = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = '2'
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_user(day0,month0,
                year0,day1,
                month1,year1,
                search_EQ_userType,
                search_EQ_batchFlag,
                search_EQ_source,
                search_EQ_autharchiveId,
                search_EQ_status,
                search_EQ_formReport,
                search_EQ_queryType,
                search_EQ_queryFormat,
                search_GTE_updateTime_DATE,
                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual(tmp, ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_byuser_year(self):
        '''按用户统计--年'''
        tmp = time.strftime('%Y',time.localtime())
        day0 = ''
        month0 = ''
        year0 = ''
        day1 = tmp
        month1 = ''
        year1 = tmp
        search_EQ_queryType = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = '3'
        search_EQ_userType = self.file_data.get('search_EQ_userType')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_user(day0,month0,
                year0,day1,
                month1,year1,
                search_EQ_userType,
                search_EQ_batchFlag,
                search_EQ_source,
                search_EQ_autharchiveId,
                search_EQ_status,
                search_EQ_formReport,
                search_EQ_queryType,
                search_EQ_queryFormat,
                search_GTE_updateTime_DATE,
                search_LTE_updateTime_DATE,self.cookie)
        Log.info(ret)
        self.assertEqual(tmp, ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_exportbyorg(self):
        '''按机构统计导出'''
        day0 = datetime.date.today()
        day1 = datetime.date.today()
        month0  = self.file_data.get('month0')
        year0  = self.file_data.get('year0')
        year1  = self.file_data.get('year1')
        month1  = self.file_data.get('month1')
        search_EQ_operOrg = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = datetime.date.today()
        search_LTE_updateTime_DATE = datetime.date.today()
        ret = EntStatisticsRequest.exportbyorg(day0,
                     month0, year0,
                     day1, month1,
                     year1,
                     search_EQ_operOrg,
                     search_EQ_batchFlag,
                     search_EQ_source,
                     search_EQ_autharchiveId,
                     search_EQ_status,
                     search_EQ_formReport,
                     search_EQ_queryFormat,
                     search_GTE_updateTime_DATE,
                     search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        size = download('企业按机构统计报表dhcc_ent_statisticsDtest_exportbyorg%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_byorg_nodate(self):
        '''按机构统计无起始结束日期'''
        day0 = ''
        day1 = ''
        month0  = ''
        year0  = ''
        year1  = ''
        month1  = ''
        search_EQ_operOrg = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = ''
        search_LTE_updateTime_DATE = ''
        ret = EntStatisticsRequest.statistics_by_org(day0,
            month0,year0,
            day1,month1,
            year1,search_EQ_operOrg,
            search_EQ_batchFlag,
            search_EQ_source,
            search_EQ_autharchiveId,
            search_EQ_status,
            search_EQ_formReport,
            search_EQ_queryFormat,
            search_GTE_updateTime_DATE,
            search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('请选择开始时间及结束时间', ret.msg)

    def test_byorg_nodata(self):
        '''按机构统计无数据'''
        tmp = '2009-12-12'
        day0 = tmp
        day1 = tmp
        month0  = ''
        year0  = ''
        year1  = ''
        month1  = ''
        search_EQ_operOrg = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_org(day0,
            month0,year0,
            day1,month1,
            year1,search_EQ_operOrg,
            search_EQ_batchFlag,
            search_EQ_source,
            search_EQ_autharchiveId,
            search_EQ_status,
            search_EQ_formReport,
            search_EQ_queryFormat,
            search_GTE_updateTime_DATE,
            search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('未查询到相关数据', ret.msg)

    def test_byorg_day(self):
        '''按机构统计--天'''
        tmp = time.strftime('%Y-%m-%d',time.localtime())
        day0 = tmp
        day1 = tmp
        month0  = ''
        year0  = ''
        year1  = ''
        month1  = ''
        search_EQ_operOrg = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = self.file_data.get('search_EQ_formReport')
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_org(day0,
            month0,year0,
            day1,month1,
            year1,search_EQ_operOrg,
            search_EQ_batchFlag,
            search_EQ_source,
            search_EQ_autharchiveId,
            search_EQ_status,
            search_EQ_formReport,
            search_EQ_queryFormat,
            search_GTE_updateTime_DATE,
            search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual(tmp, ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_byorg_month(self):
        '''按机构统计--月'''
        tmp = time.strftime('%Y-%m',time.localtime())
        day0 = tmp
        day1 = tmp
        month0  = ''
        year0  = ''
        year1  = ''
        month1  = ''
        search_EQ_operOrg = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = '2'
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_org(day0,
            month0,year0,
            day1,month1,
            year1,search_EQ_operOrg,
            search_EQ_batchFlag,
            search_EQ_source,
            search_EQ_autharchiveId,
            search_EQ_status,
            search_EQ_formReport,
            search_EQ_queryFormat,
            search_GTE_updateTime_DATE,
            search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual(tmp, ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_byorg_year(self):
        '''按机构统计--年'''
        tmp = time.strftime('%Y',time.localtime())
        day0 = tmp
        day1 = tmp
        month0  = ''
        year0  = ''
        year1  = ''
        month1  = ''
        search_EQ_operOrg = ''
        search_EQ_batchFlag = self.file_data.get('search_EQ_batchFlag')
        search_EQ_source = self.file_data.get('search_EQ_source')
        search_EQ_autharchiveId = self.file_data.get('search_EQ_autharchiveId')
        search_EQ_status = self.file_data.get('search_EQ_status')
        search_EQ_formReport = '3'
        search_EQ_queryFormat = '00'
        search_GTE_updateTime_DATE = tmp
        search_LTE_updateTime_DATE = tmp
        ret = EntStatisticsRequest.statistics_by_org(day0,
            month0,year0,
            day1,month1,
            year1,search_EQ_operOrg,
            search_EQ_batchFlag,
            search_EQ_source,
            search_EQ_autharchiveId,
            search_EQ_status,
            search_EQ_formReport,
            search_EQ_queryFormat,
            search_GTE_updateTime_DATE,
            search_LTE_updateTime_DATE, self.cookie)
        Log.info(ret)
        self.assertEqual(tmp, ret.date[0])
        self.assertIsNotNone(ret.data[0].dataList[0].queryReason)

    def test_statistics_by_rule_nodate(self):
        '''违规分析统计无起始结束日期'''
        search_GTE_startDate_DATE = ''
        search_GTE_alertDate_DATE =''
        search_IN_deptCode = ''
        ret = EntStatisticsRequest.statistics_by_rule(search_GTE_startDate_DATE,
                                                search_GTE_alertDate_DATE,
                                                search_IN_deptCode,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('请选择开始时间及结束时间', ret.msg)

    def test_statistics_by_rule_nodata(self):
        '''违规分析统计空数据'''
        tmp = '2020-01-02'
        search_GTE_startDate_DATE = tmp
        search_GTE_alertDate_DATE = tmp
        search_IN_deptCode = ''
        ret = EntStatisticsRequest.statistics_by_rule(search_GTE_startDate_DATE,
                                                search_GTE_alertDate_DATE,
                                                search_IN_deptCode,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001', ret.code)
        self.assertEqual('您输入的查询条件没有查询到结果，请确认核对', ret.msg)


if __name__ == "__main__":
    pass